package com.cn.springcloudwechat.controller.courseall;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.mybatis.Page;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.model.YmCourse;
import com.cn.springcloudwechat.model.YmCoursePackage;
import com.cn.springcloudwechat.service.courseall.CoursePackageService;


@Controller
@RequestMapping("/course")
@ResponseBody
public class CoursePackageController {

	@Autowired
	CoursePackageService coursePackageService;
	
	 /**
	 * 课程包的发布
      *
	 * @return SUCC
	 */
	@RequestMapping("/insertCoursePackage")
    public AjaxRes insertCoursePackage(AjaxRes ajaxRes,YmCoursePackage ymcoursePackage,@RequestParam("parameter[]")String[] parameter){
        try {
            Long ymcoursePackageId = this.coursePackageService.insertCoursePackageSer(ymcoursePackage, parameter);
            ajaxRes.setSucceed(ymcoursePackageId,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	
	/**
	 * 课程包的查询
     *
	 * @return List<YmCoursePackage>
	 */
	@RequestMapping("/queryCoursePackage")
    public AjaxRes queryCoursePackage(AjaxRes ajaxRes,YmCoursePackage ymcoursePackage,Page<Object> page){
        try { 
        	Page<Object> ymCoursePackages = this.coursePackageService.queryCoursePackageSer(ymcoursePackage,page);
            ajaxRes.setSucceed(ymCoursePackages,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	
	/**
	 * 课程包的查询(明细*课程包下面的课程明细)
     *
	 * @return List<YmCoursePackage>
	 */
	@RequestMapping("/queryCoursePackageDetail")
    public AjaxRes queryCoursePackageDetail(AjaxRes ajaxRes,Long coursePackageId){
        try {
        	List<YmCoursePackage> ymCoursePackages = this.coursePackageService.queryCoursePackageDetailSer(coursePackageId);
            ajaxRes.setSucceed(ymCoursePackages,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	 
	/**
	 * 课程包的修改
	 * 
	 * @return SUCC
	 */
	@RequestMapping("updateCoursePackage")
    public AjaxRes updateCoursePackage(AjaxRes ajaxRes,YmCoursePackage ymcoursePackage,@RequestParam("parameter[]")String[] parameter){
        try {
        	this.coursePackageService.updateCoursePackageSer(ymcoursePackage,parameter);
            ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	
	/**
	 * 课程包的修改(状态调整)
	 * 
	 * @return SUCC
	 */
	@RequestMapping("updateCoursePackageState")
    public AjaxRes updateCoursePackageState(AjaxRes ajaxRes,Integer state,@RequestParam("parameter[]")String[] parameter){
        try {
        	this.coursePackageService.updateCoursePackageStateSer(state,parameter);
            ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	
	/**
	 * 课程包的收藏数量
     *
	 * @return SUCC
	 */
	@RequestMapping("updateCollectionNumber")
    public AjaxRes updateCollectionNumber(AjaxRes ajaxRes,Long coursePackageId){
        try {
        	this.coursePackageService.updateCollectionNumberSer(coursePackageId);
            ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	/**
	 * 课程发布
	 * 
	 * @return SUCC
	 */
	@RequestMapping("/insertCourse")
    public AjaxRes insertCourse(AjaxRes ajaxRes,YmCourse ymCourse){
        try {
            Long ymCourseId = this.coursePackageService.insertCourseSer(ymCourse);
            ajaxRes.setSucceed(ymCourseId,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	
	/**
	 * 课程的查询
	 * 
	 * @return List<YmCourse>
	 */
	@RequestMapping("/queryCourse")
    public AjaxRes queryCourse(AjaxRes ajaxRes,YmCourse ymcourse,Page<Object> page){
        try {
        	Page<Object> ymCourses = this.coursePackageService.queryCourseSer(ymcourse,page);
            ajaxRes.setSucceed(ymCourses,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	
	/**
	 * 课程的修改(状态有效无效)
	 * 
	 * @return SUCC
	 */
	@RequestMapping("/updateCourse")
    public AjaxRes updateCourse(AjaxRes ajaxRes,YmCourse ymCourse){
        try {
        	this.coursePackageService.updateCourseSer(ymCourse);
            ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	
	/**
	 * 课程的修改(状态有效无效)
	 * 
	 * @return SUCC
	 */
	@RequestMapping("/updateCourseState")
    public AjaxRes updateCourseState(AjaxRes ajaxRes,@RequestParam("parameter[]")String[] parameter,Integer state){
        try {
        	this.coursePackageService.updateCourseStateSer(parameter,state);
            ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
}
